home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / infodata / callbook.tar / callbook_1.3 / print.c < prev    next >
C/C++ Source or Header  |  1991-03-31  |  6KB  |  373 lines

  1. /*
  2.  * Telnet callsign server sources copyright 1989 by Devon Bowen, KA2NRC.
  3.  * You may distribute and modify these files as you please as long as
  4.  * as long as credit to the original creator is given. Please report any
  5.  * bug fixes or modification to bowen@cs.buffalo.edu.
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <ctype.h>
  10.  
  11. #include "callbook.h"
  12.  
  13. char *index(), *cvtdate();
  14. int p_data(), p_name(), p_raw(), p_addr();
  15.  
  16. int (*p_routine[])() = { p_data, p_name, p_raw, p_addr };
  17.  
  18. p_name(buffer, not_first)
  19. char *buffer;
  20. int not_first;
  21. {
  22.     int count;
  23.     char *fields[19];
  24.     char temp[BUFSIZ];
  25.  
  26.     fields[0] = buffer;
  27.  
  28.     for (count=1; count<19; count++) {
  29.         fields[count] = index(fields[count-1], '|');
  30.         *(fields[count]++) = '\0';
  31.     }
  32.  
  33.     sprintf(temp, "%-13s%s ", fields[0], fields[3]);
  34.  
  35.     if (*fields[4]) {
  36.         strcat(temp, fields[4]);
  37.         strcat(temp, " ");
  38.     }
  39.  
  40.     if (*fields[1]) {
  41.         strcat(temp, fields[1]);
  42.         strcat(temp, " ");
  43.     }
  44.  
  45.     if (*fields[2])
  46.         strcat(temp, fields[2]);
  47.  
  48.     strcat(temp, "\n");
  49.  
  50.     if (tputs(temp, 0))
  51.         return 1;
  52.  
  53.     return 0;
  54. }
  55.  
  56.  
  57. p_raw(buffer, not_first)
  58. char *buffer;
  59. int not_first;
  60. {
  61.     if (tputs(buffer, 0))
  62.         return 1;
  63.  
  64.     if (tputs("\n", 0))
  65.         return 1;
  66.  
  67.     return 0;
  68. }
  69.  
  70.  
  71. p_data(buffer, not_first)
  72. char *buffer;
  73. int not_first;
  74. {
  75.     int count, was_call=0;
  76.     char *fields[19];
  77.     char temp1[BUFSIZ];
  78.     char temp2[BUFSIZ];
  79.  
  80.     fields[0] = buffer;
  81.     while (isspace(*fields[0]))
  82.         fields[0]++;
  83.  
  84.     for (count=1; count<19; count++) {
  85.         fields[count] = index(fields[count-1], '|');
  86.         *(fields[count]++) = '\0';
  87.         while (*fields[count] == ' ')
  88.             fields[count]++;
  89.     }
  90.  
  91.     if (not_first)
  92.         if (tputs("\n", 0))
  93.             return 1;
  94.  
  95.     sprintf(temp2, "Call-Sign: %-25s", fields[0]);
  96.  
  97.     switch (*fields[15]) {
  98.  
  99.         case 'N' : strcat(temp2, "Class: NOVICE\n");
  100.                was_call=1;
  101.                break;
  102.  
  103.         case 'T' : strcat(temp2, "Class: TECHNICIAN\n");
  104.                was_call=1;
  105.                break;
  106.  
  107.         case 'G' : strcat(temp2, "Class: GENERAL\n");
  108.                was_call=1;
  109.                break;
  110.  
  111.         case 'A' : strcat(temp2, "Class: ADVANCED\n");
  112.                was_call=1;
  113.                break;
  114.  
  115.         case 'E' : strcat(temp2, "Class: EXTRA\n");
  116.                was_call=1;
  117.                break;
  118.  
  119.         default  : strcat(temp2, "\n");
  120.                break;
  121.     }
  122.  
  123.     if (tputs(temp2, 0))
  124.         return 1;
  125.  
  126.     if (*fields[16] || *fields[17]) {
  127.  
  128.         sprintf(temp2, "Previously: %-24s",
  129.             (*fields[16] ? fields[16] : "SAME CALL"));
  130.  
  131.         if (*fields[17])
  132.             switch (*fields[17]) {
  133.         
  134.             case 'N' :
  135.                 strcat(temp2, "Class: NOVICE\n");
  136.                 break;
  137.  
  138.             case 'T' :
  139.                 strcat(temp2, "Class: TECHNICIAN\n");
  140.                 break;
  141.  
  142.             case 'G' :
  143.                 strcat(temp2, "Class: GENERAL\n");
  144.                 break;
  145.  
  146.             case 'A' :
  147.                 strcat(temp2, "Class: ADVANCED\n");
  148.                 break;
  149.  
  150.             case 'E' :
  151.                 strcat(temp2, "Class: EXTRA\n");
  152.                 break;
  153.             }
  154.  
  155.         else
  156.             if (was_call)
  157.                 strcat(temp2, "Class: SAME CLASS\n");
  158.             else
  159.                 strcat(temp2, "\n");
  160.  
  161.         if (tputs(temp2, 0))
  162.             return 1;
  163.     }
  164.  
  165.     strcpy(temp1, fields[3]);
  166.  
  167.     if (*fields[4]) {
  168.         strcat(temp1, " ");
  169.         strcat(temp1, fields[4]);
  170.     }
  171.  
  172.     if (*fields[1]) {
  173.         strcat(temp1, " ");
  174.         strcat(temp1, fields[1]);
  175.     }
  176.  
  177.     if (*fields[2]) {
  178.         strcat(temp1, " ");
  179.         strcat(temp1, fields[2]);
  180.     }
  181.  
  182.     sprintf(temp2, "Real Name: %-25s", temp1);
  183.  
  184.     if (*fields[5]) {
  185.         sprintf(temp1, "Birthday: %s\n", cvtdate(fields[5],1));
  186.         strcat(temp2, temp1);
  187.     } else
  188.         strcat(temp2, "\n");
  189.  
  190.     if (tputs(temp2, 0))
  191.         return 1;
  192.  
  193.     if (*fields[8] || *fields[9] || *fields[10] || *fields[11]) {
  194.  
  195.         strcpy(temp2, "Mailing Address: ");
  196.  
  197.         if (*fields[8]) {
  198.             strcat(temp2, fields[8]);
  199.             strcat(temp2, ", ");
  200.         }
  201.  
  202.         if (*fields[9]) {
  203.             strcat(temp2, fields[9]);
  204.             strcat(temp2, ", ");
  205.         }
  206.  
  207.         if (*fields[10]) {
  208.             strcat(temp2, fields[10]);
  209.             strcat(temp2, "  ");
  210.         }
  211.  
  212.         if (*fields[11]) {
  213.             strcat(temp2, fields[11]);
  214.         }
  215.  
  216.         strcat(temp2, "\n");
  217.  
  218.         if (tputs(temp2, 0))
  219.             return 1;
  220.     }
  221.  
  222.     if (*fields[12] || *fields[13] || *fields[14]) {
  223.  
  224.         strcpy(temp2, "Station Address: ");
  225.  
  226.         if (*fields[12] == '*') {
  227.             strcat(temp2, "SAME AS MAILING ADDRESS\n");
  228.  
  229.         } else {
  230.  
  231.             if (*fields[12]) {
  232.                 strcat(temp2, fields[12]);
  233.                 strcat(temp2, ", ");
  234.             }
  235.  
  236.             if (*fields[13]) {
  237.                 strcat(temp2, (*fields[13]=='*' ? fields[9] :
  238.                                 fields[13]));
  239.                 strcat(temp2, ", ");
  240.             }
  241.  
  242.             if (*fields[14])
  243.                 strcat(temp2, (*fields[14]=='*' ? fields[10] :
  244.                                 fields[14]));
  245.  
  246.             strcat(temp2, "\n");
  247.         }
  248.  
  249.         if (tputs(temp2, 0))
  250.             return 1;
  251.     }
  252.  
  253.     if (*fields[6]) {
  254.         sprintf(temp2, "Valid From: %-24s", cvtdate(fields[6],1));
  255.  
  256.         if (*fields[7]) {
  257.             strcat(temp2, "To: ");
  258.             strcat(temp2, cvtdate(fields[7],0));
  259.         }
  260.  
  261.         strcat(temp2, "\n");
  262.         if (tputs(temp2, 0))
  263.             return 1;
  264.     }
  265.  
  266.     if (*fields[18] && (*fields[18] != '*' || *fields[6])) {
  267.         sprintf(temp2, "Records Last Processed: %s\n",
  268.             (*fields[18] == '*' ? cvtdate(fields[6],1) :
  269.                             cvtdate(fields[18],1)));
  270.  
  271.         if (tputs(temp2, 0))
  272.             return 1;
  273.     }
  274.  
  275.     return 0;
  276. }
  277.  
  278.  
  279. p_addr(buffer, not_first)
  280. char *buffer;
  281. int not_first;
  282. {
  283.     int count;
  284.     char *fields[19];
  285.     char temp[BUFSIZ];
  286.  
  287.     fields[0] = buffer;
  288.  
  289.     for (count=1; count<19; count++) {
  290.         fields[count] = index(fields[count-1], '|');
  291.         *(fields[count]++) = '\0';
  292.     }
  293.  
  294.     if (!not_first)
  295.         if (tputs("\n", 0))
  296.             return 1;
  297.  
  298.     strcpy(temp, fields[3]);
  299.  
  300.     if (*fields[4]) {
  301.         strcat(temp, " ");
  302.         strcat(temp, fields[4]);
  303.     }
  304.  
  305.     if (*fields[1]) {
  306.         strcat(temp, " ");
  307.         strcat(temp, fields[1]);
  308.     }
  309.  
  310.     if (*fields[2]) {
  311.         strcat(temp, " ");
  312.         strcat(temp, fields[2]);
  313.     }
  314.  
  315.     strcat(temp, " (");
  316.     strcat(temp, fields[0]);
  317.     strcat(temp, ")\n");
  318.  
  319.     if (tputs(temp, 0))
  320.         return 1;
  321.  
  322.     if (tputs(fields[8], 0))
  323.         return 1;
  324.  
  325.     if (tputs("\n", 0))
  326.         return 1;
  327.  
  328.     sprintf(temp, "%s, %s  %s\n\n", fields[9], fields[10], fields[11]);
  329.  
  330.     if (tputs(temp, 0))
  331.         return 1;
  332.  
  333.     return 0;
  334. }
  335.  
  336.  
  337. #define isleap(y) (((y) % 4) == 0 && ((y) % 100) != 0 || ((y) % 400) == 0)
  338. #define CENTURY 20
  339.  
  340. char *
  341. cvtdate(s,before)
  342. char *s;
  343. int before;
  344. {
  345.     static char buf[BUFSIZ];
  346.     register char *cp;
  347.     int day, year;
  348.  
  349.     static struct month {
  350.         char *name;
  351.         int days;
  352.     } *mp, mtab[] = {
  353.         "JAN",31,"FEB",28,"MAR",31,"APR",30,"MAY",31,"JUN",30,
  354.         "JUL",31,"AUG",31,"SEP",30,"OCT",31,"NOV",30,"DEC",31
  355.     };
  356.  
  357.     strcpy(buf, s);
  358.     cp = buf;
  359.     cp += 2;
  360.     day = atoi(cp);
  361.     *cp = '\0';
  362.     year = (CENTURY - 1) * 100 + atoi(buf);
  363.     if (year > DB_YEAR && before) year -= 100;
  364.     if (year < DB_YEAR && !before) year += 100;
  365.  
  366.     mtab[1].days = isleap(year) ? 29 : 28;
  367.     for (mp = mtab; day > mp->days; mp++)
  368.         day -= mp->days;
  369.  
  370.     sprintf(buf, "%s %d, %d", mp->name, day, year);
  371.     return(buf);
  372. }
  373.